//
//  CYStatusRetweetedView.swift
//  CYSinaWB
//
//  Created by mac on 16/2/26.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit

class CYStatusRetweetedView: UIView {
    
    var bottomConstraint: Constraint?
    
    var retweetedStatus: CYStatus? {
        didSet {
            retweetedLabel.text = retweetedStatus?.text
            pictureView.imageUrls = retweetedStatus?.imageUrls
            
            self.bottomConstraint?.uninstall()
            if let reUrls = retweetedStatus?.imageUrls where reUrls.count != 0 {
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(statusCellMargin).constraint
                })
            } else {
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(statusCellMargin).constraint
                })
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.brownColor()
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUpUI() {
        addSubview(retweetedLabel)
        addSubview(pictureView)
        
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(statusCellMargin)
            make.right.equalTo(self.snp_right).offset(-statusCellMargin)
            make.top.equalTo(self.snp_top).offset(statusCellMargin)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedLabel.snp_left)
            make.top.equalTo(retweetedLabel.snp_bottom).offset(statusCellMargin)
        }
        
        self.snp_makeConstraints { (make) -> Void in
          self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(statusCellMargin).constraint
        }
        
    }
    
    private lazy var retweetedLabel: UILabel = UILabel(text: "hahahhahah", fontSize: 14, textColor: UIColor.darkGrayColor(), alignment: NSTextAlignment.Left)
    
    private lazy var pictureView: CYStatusPictureView = CYStatusPictureView()
}
